home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / hardware / cpu115 / cputype.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-27  |  3.7 KB  |  128 lines

  1. /* ------------------------------------------------------------------------- *
  2.  * CPUTYPE.C  CPU/FPU detection routines                     *
  3.  *                                         *
  4.  * Copyright(c) 1994,95 by B-coolWare.  Written by Bobby Z. and VAP.         *
  5.  * Uses portions of TMi0SDGL(tm) v1.15                         *
  6.  * ------------------------------------------------------------------------- *
  7.  * files needed to build:
  8.    
  9.    CPUTYPE.C        - compile with memory model XXX
  10.    CPU_HL.ASM        - set memory model to XXX
  11.    CPUSPEED.ASM        - set memory model to XXX
  12.    P5INFO.ASM        - set memory model to XXX
  13.    SMM.ASM        - set memory model to XXX
  14. */
  15.  
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. #define __Lib__
  20. #include "cputype.h"
  21.  
  22. byte pascal FPUType = 0xFF;    /* variable to keep FPU test result code */
  23. long pascal CPUFix  = 0L;    /* variable used internally in CPU speed testing */
  24. word pascal Shift   = 2;    /* --"-- */
  25.  
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. extern int pascal Speed( byte );         /* returns raw CPU speed factor */
  30. extern word pascal GetP5Features(void);         /* returns P5 feature word */
  31. extern void pascal GetP5Vendor(char far *);  /* returns CPU vendor id string */
  32. extern word pascal CheckP5(void);         /* checks if cpuid works */
  33. #ifdef __cplusplus
  34. }
  35. #endif
  36.  
  37. void pascal checkUMC(void)
  38. {
  39.  char s[14];
  40.  if(__CPU >= i486sxr)
  41.   if(CheckP5()==0x423)
  42.    {
  43.     GetP5Vendor(s);
  44.     s[13]=0;
  45.     if(strstr(s+1,"UMC")!=0L)
  46.      if(GetP5Features() & 1)
  47.       __CPU = 0x14;
  48.      else
  49.       __CPU = 0x13;
  50.    }
  51. }
  52.  
  53. float pascal CPU_Speed(void)
  54. {
  55.  word sp;
  56.  if(!__CPU)
  57.   return 0;
  58.  sp = Speed(__CPU);
  59.  return (((long)Shift*CPUFix)/sp+5)/10;
  60. }
  61.  
  62. int pascal intCPU_Speed(void)
  63. {
  64.  long sp;
  65.  if(!__CPU)
  66.   return 0;
  67.  sp = (long) Speed(__CPU);
  68.  return (int) ((((long)Shift*CPUFix)/sp+5l)/10l);
  69. }
  70.  
  71. static char *cpuNames[] = {"Intel 8088", "Intel 8086", "NEC V20", "NEC V30",
  72.                    "Intel 80188", "Intel 80186", "Intel 80286", "Intel 80386SX",
  73.                    "Intel 80386DX", "IBM 386SL", "Intel i486SX", "Intel i486DX",
  74.                    "Cyrix 486SLC", "Cyrix 486", "Intel Pentium", "Cyrix M1 (586)",
  75.                    "Intel P24D (Pentium Overdrive)","AMD Am386SX","AMD Am386DX",
  76.                            "UMC U5-S","UMC U5-D"
  77.            };
  78.  
  79. static char *cpuModels[] = {"DX","DX","SX","DX2/Overdrive","SL","SX2","","","DX4","","","","","","","" };
  80.  
  81.  
  82. char * pascal cpuType_Str(void)
  83. {
  84.   word c = CPU_Type();
  85.   __CPU = c;
  86.   checkUMC();
  87.   if (__CPU == 0x0A && (c>>12))
  88.    return strcat("Intel i486",cpuModels[c >> 12]);
  89.   switch(c) {
  90.    case i80386sxr:
  91.    case i80386sxv: if (intCPU_Speed() > 35)
  92.              return cpuNames[0x11];
  93.            else
  94.              return cpuNames[__CPU];
  95.    case i80386dxr:
  96.    case i80386dxv: if (intCPU_Speed() > 35)
  97.             return cpuNames[0x12];
  98.            else
  99.             return cpuNames[__CPU];
  100.    default:
  101.                return cpuNames[__CPU];
  102.   }
  103. }
  104.  
  105. static char *fpuNames[] = {"Unknown!", "Unknown!", "None", "Weitek", "Intel 8087",
  106.                    "Intel 8087 & Weitek", "Intel i487sx", "Intel i487sx & Weitek",
  107.                    "Intel 80287", "Intel 80287 & Weitek", "Cyrix 2C87",
  108.                    "Cyrix 2C87 & Weitek", "Intel 80387", "Intel 80387 & Weitek",
  109.                    "Cyrix 3C87", "Cyrix 3C87 + Weitek", "Built-in",
  110.                    "Built-in & Weitek", "Cyrix 4C87", "Cyrix 4C87 & Weitek",
  111.                    "Intel 80287XL", "Intel 80287XL & Weitek",
  112.                    "IIT 2C87", "IIT 2C87 & Weitek", "IIT 3C87", "IIT 3C87 & Weitek"
  113.                    };
  114.  
  115.  
  116. char * pascal fpuType_Str(void)
  117. {
  118.  
  119.   int c = CPU_Type();
  120.   if (FPUType > 25) 
  121.    return ("Unknown!");
  122.   else
  123.    if ((c >= i80286) && checkEmu())
  124.     return strcat(fpuNames[FPUType],", Emulated");
  125.    else
  126.     return fpuNames[FPUType];
  127. }
  128.